home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / pmb_dhry_1.c < prev    next >
C/C++ Source or Header  |  1996-05-20  |  12KB  |  376 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *                   "DHRYSTONE" Benchmark Program
  5.  *                   -----------------------------
  6.  *
  7.  *  Version:    C, Version 2.1
  8.  *
  9.  *  File:       dhry_1.c (part 2 of 3)
  10.  *
  11.  *  Date:       May 25, 1988
  12.  *
  13.  *  Author:     Reinhold P. Weicker
  14.  *
  15.  *************************************************************************
  16.  */
  17.  
  18. #include "pmb_dhry.h"
  19.  
  20. /* Global Variables: */
  21.  
  22. static Rec_Pointer     Ptr_Glob,
  23.                 Next_Ptr_Glob;
  24. int             Int_Glob;
  25. static Boolean         Bool_Glob;
  26. char            Ch_1_Glob;
  27. static char            Ch_2_Glob;
  28. static int             Arr_1_Glob [50];
  29. static int             Arr_2_Glob [50] [50];
  30.  
  31. extern char     *malloc ();
  32. Enumeration     PFunc_1 ();
  33.   /*
  34.   forward declaration necessary since Enumeration may not simply be int
  35.   */
  36.  
  37. #ifndef ROPT
  38. #define REG
  39.         /* REG becomes defined as empty */
  40.         /* i.e. no register variables   */
  41. #else
  42. #define REG register
  43. #endif
  44.  
  45. /* variables for time measurement: */
  46.  
  47. #define Too_Small_Time 2
  48.                 /* Measurements should last at least 2 seconds */
  49.  
  50. static double          Begin_Time,
  51.                 End_Time,
  52.                 User_Time;
  53.  
  54. static double          Microseconds,
  55.                 Dhrystones_Per_Second,
  56.                 Vax_Mips;
  57. REG    int      Pnumber_of_runs;
  58.  
  59. /* end of variables for time measurement */
  60.  
  61.  
  62. double pmb_dhry(int nofr)
  63. /*****/
  64.  
  65.   /* main program, corresponds to procedures        */
  66.   /* Main and Proc_0 in the Ada version             */
  67. {
  68.   double   dtime();
  69.  
  70.         One_Fifty       Int_1_Loc;
  71.   REG   One_Fifty       Int_2_Loc;
  72.         One_Fifty       Int_3_Loc;
  73.   REG   char            Ch_Index;
  74.         Enumeration     Enum_Loc;
  75.         Str_30          Str_1_Loc;
  76.         Str_30          Str_2_Loc;
  77.   REG   int             Run_Index;
  78.   REG   int             Pnumber_of_runs;
  79.  
  80.   /* Initializations */
  81.  
  82.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  83.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  84.  
  85.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  86.   Ptr_Glob->Discr                       = Ident_1;
  87.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  88.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  89.   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  90.           "DHRYSTONE PROGRAM, SOME STRING");
  91.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  92.  
  93.   Arr_2_Glob [8][7] = 10;
  94.         /* Was missing in published program. Without this statement,    */
  95.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  96.         /* Warning: With 16-Bit processors and Pnumber_of_runs > 32000,  */
  97.         /* overflow may occur for this array element.                   */
  98.  
  99. //  printf ("\n");
  100. //  printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  101. //  printf ("\n");
  102. /*
  103.   if (Reg)
  104.   {
  105.     printf ("Program compiled with 'register' attribute\n");
  106.     printf ("\n");
  107.   }
  108.   else
  109.   {
  110.     printf ("Program compiled without 'register' attributen");
  111.     printf ("n");
  112.   }
  113. */
  114. //  printf ("Please give the number of runs through the benchmark: ");
  115.   {
  116.     int n;
  117.     //scanf ("%d", &n);
  118.     Pnumber_of_runs = nofr; // HCH
  119.   }
  120. //  printf ("\n");
  121.  
  122. //  printf ("Execution starts, %d runs through Dhrystone\n",Pnumber_of_runs);
  123.  
  124.   /***************/
  125.   /* Start timer */
  126.   /***************/
  127.  
  128.   Begin_Time = dtime();
  129.  
  130.   for (Run_Index = 1; Run_Index <= Pnumber_of_runs; ++Run_Index)
  131.   {
  132.  
  133.     Proc_5();
  134.     Proc_4();
  135.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  136.     Int_1_Loc = 2;
  137.     Int_2_Loc = 3;
  138.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  139.     Enum_Loc = Ident_2;
  140.     Bool_Glob = ! PFunc_2 (Str_1_Loc, Str_2_Loc);
  141.       /* Bool_Glob == 1 */
  142.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  143.     {
  144.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  145.         /* Int_3_Loc == 7 */
  146.       PProc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  147.         /* Int_3_Loc == 7 */
  148.       Int_1_Loc += 1;
  149.     } /* while */
  150.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  151.     PProc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  152.       /* Int_Glob == 5 */
  153.     Proc_1 (Ptr_Glob);
  154.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  155.                              /* loop body executed twice */
  156.     {
  157.       if (Enum_Loc == PFunc_1 (Ch_Index, 'C'))
  158.           /* then, not executed */
  159.         {
  160.         PProc_6 (Ident_1, &Enum_Loc);
  161.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  162.         Int_2_Loc = Run_Index;
  163.         Int_Glob = Run_Index;
  164.         }
  165.     }
  166.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  167.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  168.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  169.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  170.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  171.     Proc_2 (&Int_1_Loc);
  172.       /* Int_1_Loc == 5 */
  173.  
  174.   } /* loop "for Run_Index" */
  175.  
  176.   /**************/
  177.   /* Stop timer */
  178.   /**************/
  179.  
  180.   End_Time = dtime();
  181. /*
  182.   printf ("Execution ends\n");
  183.   printf ("\n");
  184.   printf ("Final values of the variables used in the benchmark:\n");
  185.   printf ("\n");
  186.   printf ("Int_Glob:            %d\n", Int_Glob);
  187.   printf ("        should be:   %d\n", 5);
  188.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  189.   printf ("        should be:   %d\n", 1);
  190.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  191.   printf ("        should be:   %c\n", 'A');
  192.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  193.   printf ("        should be:   %c\n", 'B');
  194.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  195.   printf ("        should be:   %d\n", 7);
  196.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  197.   printf ("        should be:   Pnumber_of_runs + 10\n");
  198.   printf ("Ptr_Glob->\n");
  199.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  200.   printf ("        should be:   (implementation-dependent)\n");
  201.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  202.   printf ("        should be:   %d\n", 0);
  203.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  204.   printf ("        should be:   %d\n", 2);
  205.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  206.   printf ("        should be:   %d\n", 17);
  207.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  208.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  209.   printf ("Next_Ptr_Glob->\n");
  210.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  211.   printf ("        should be:   (implementation-dependent), same as above\n");
  212.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  213.   printf ("        should be:   %d\n", 0);
  214.   printf ("  Enum_Comp:         %d\n",
  215.          Next_Ptr_Glob->variant.var_1.Enum_Comp);
  216.   printf ("        should be:   %d\n", 1);
  217.   printf ("  Int_Comp:          %d\n",
  218.          Next_Ptr_Glob->variant.var_1.Int_Comp);
  219.   printf ("        should be:   %d\n", 18);
  220.   printf ("  Str_Comp:          %s\n",
  221.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  222.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  223.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  224.   printf ("        should be:   %d\n", 5);
  225.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  226.   printf ("        should be:   %d\n", 13);
  227.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  228.   printf ("        should be:   %d\n", 7);
  229.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  230.   printf ("        should be:   %d\n", 1);
  231.   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
  232.   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
  233.   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
  234.   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
  235.   printf ("\n");
  236. */
  237.   User_Time = End_Time - Begin_Time;
  238.  
  239.   if (User_Time < Too_Small_Time)
  240.   {
  241. /*    printf ("Measured time too small to obtain meaningful results\n");
  242.     printf ("Please increase number of runs\n");
  243.     printf ("\n"); */
  244.     return -1.0;
  245.   }
  246.   els